package com.example.customviewtest.api

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.VelocityTracker
import android.view.View
import android.view.ViewTreeObserver
import android.widget.Scroller
import com.example.customviewtest.R
import kotlinx.android.synthetic.main.activity_a_p_i.*

class APIActivity : AppCompatActivity() {
    lateinit var velocityTracker: VelocityTracker
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_a_p_i)
        velocityTracker = VelocityTracker.obtain()

//        touch_test()
        scroll_test()
//        move_test()

    }

    private fun move_test() {
        view.scrollTo(200, 100)

    }

    private fun scroll_test() {
        val scroller = Scroller(this)

    }

    private fun touch_test() {
        view.setOnTouchListener(object : View.OnTouchListener {
            override fun onTouch(v: View?, event: MotionEvent): Boolean {
                val action = event.action
                velocityTracker.addMovement(event)
                velocityTracker.computeCurrentVelocity(1000)
                when (action) {
                    MotionEvent.ACTION_DOWN -> {
                        val x = event.x
                        val y = event.getY()
                        val rawX = event.rawX
                        val rawY = event.getRawY()
                        Log.i("xd----", "x=" + x + ",y=" + y)
                        Log.i("xd----", "rawX=" + rawX + ",raeY=" + rawY)

                    }
                    MotionEvent.ACTION_MOVE -> {
                        val xVelocity = velocityTracker.getXVelocity()
                        val yVelocity = velocityTracker.getYVelocity()
                        Log.i("xd----", "xVelocity=" + xVelocity + ",yVelocity=" + yVelocity)

                    }
                    MotionEvent.ACTION_UP -> {
                        val xVelocity = velocityTracker.getXVelocity()
                        val yVelocity = velocityTracker.getYVelocity()
                        Log.i("xd----", "xVelocity=" + xVelocity + ",yVelocity=" + yVelocity)

                    }
                }
                return true
            }
        })
    }
}
